<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:75:"D:\phpstudy_pro\WWW\tpshop\public/../application/admin\view\goods\edit.html";i:1581662805;s:61:"D:\phpstudy_pro\WWW\tpshop\application\admin\view\layout.html";i:1580870358;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?php echo $title; ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link href="/static/admin/css/main.css" rel="stylesheet" type="text/css"/>
    <link href="/static/admin/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="/static/admin/css/bootstrap-responsive.min.css" rel="stylesheet" type="text/css"/>
    <script src="/static/admin/js/jquery-1.8.1.min.js"></script>
    <script src="/static/admin/js/bootstrap.min.js"></script>
    <script src="/static/admin/js/highcharts.js"></script>
    <script src="/static/admin/js/exporting.js"></script>
    <script src="/static/admin/js/draw.js"></script>

</head>
<body>

    <!-- 上 -->
    <div class="navbar">
        <div class="navbar-inner">
            <div class="container-fluid">
                <ul class="nav pull-right">
                    <li id="fat-menu" class="dropdown">
                        <a href="#" id="drop3" role="button" class="dropdown-toggle" data-toggle="dropdown">
                            <i class="icon-user icon-white"></i> <?php echo \think\Session::get('info.nickname'); ?>
                            <i class="icon-caret-down"></i>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a tabindex="-1" href="javascript:void(0);">修改密码</a></li>
                            <li class="divider"></li>
                            <li><a tabindex="-1" href="<?php echo url('admin/Base/logout'); ?>">安全退出</a></li>
                        </ul>
                    </li>
                </ul>
                <a class="brand" href="index.html"><span class="first">后台管理系统</span></a>
                <ul class="nav">
                    <li class="active"><a href="javascript:void(0);">首页</a></li>
<!--                    <li><a href="javascript:void(0);">系统管理</a></li>-->
<!--                    <li><a href="javascript:void(0);">权限管理</a></li>-->
                </ul>
            </div>
        </div>
    </div>
    <!-- 左 -->
    <div class="sidebar-nav">

        <?php foreach($top_nav as $k=>$v): ?>
            <a href="#error-menu<?php echo $k; ?>" class="nav-header collapsed" data-toggle="collapse">
                <i class="icon-exclamation-sign"></i>
                <?php echo $v['auth_name']; ?>
            </a>
            <ul id="error-menu<?php echo $k; ?>" class="nav nav-list collapse in">
                <?php foreach($down_nav as $m): if($m['pid'] == $v['id']): ?>
                        <li>
                            <a href="<?php echo url('admin/'.$m['auth_c'] . '/' . $m['auth_a']); ?>">
                                <?php echo $m['auth_name']; ?>
                            </a>
                        </li>
                    <?php endif; endforeach; ?>
            </ul>
        <?php endforeach; ?>

    </div>
<script src="/plugins/ueditor/ueditor.config.js"></script>
<script src="/plugins/ueditor/ueditor.all.min.js"></script>
<script src="/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>


<!-- 右 -->
<div class="content">
    <div class="header">
        <h1 class="page-title">商品编辑</h1>
    </div>

    <!-- edit form -->
    <form action="<?php echo url('/admin/goods/update'); ?>" method="post" id="tab" enctype="multipart/form-data">
        <ul class="nav nav-tabs">
          <li role="presentation" class="active"><a href="#basic" data-toggle="tab">基本信息</a></li>
          <li role="presentation"><a href="#desc" data-toggle="tab">商品描述</a></li>
          <li role="presentation"><a href="#attr" data-toggle="tab">商品属性</a></li>
          <li role="presentation"><a href="#pics" data-toggle="tab">商品相册</a></li>
        </ul>
        <input type="hidden" name="id" value="<?php echo $goods['id']; ?>">
        <?php echo token(); ?>
        <div class="tab-content">
            <div class="tab-pane fade in active" id="basic">
                <div class="well">
                    <label>商品名称：</label>
                    <input type="text" name="goods_name" value="<?php echo $goods['goods_name']; ?>" class="input-xlarge">
                    <label>商品价格：</label>
                    <input type="text" name="goods_price" value="<?php echo $goods['goods_price']; ?>" class="input-xlarge">
                    <label>商品数量：</label>
                    <input type="text" name="goods_number" value="<?php echo $goods['goods_number']; ?>" class="input-xlarge">
                    <label>商品logo：</label>
                    <input type="file" name="goods_logo" value="" class="input-xlarge">
                    <label>商品分类：</label>
                    <select name="" id="One" class="input-xlarge">
                        <option value="">请选择一级分类</option>
                            <?php foreach($crte_one as $v): ?>
                                <option value="<?php echo $v['id']; ?>" <?php if(($v['id'] == $crte_two['pid'])): ?> selected <?php endif; ?>><?php echo $v['cate_name']; ?></option>
                            <?php endforeach; ?>
                    </select>
                    <select name="" id="Two" class="input-xlarge">
                        <option value="">请选择二级分类</option>
                            <?php foreach($crte_two_all as $v): ?>
                                <option value="<?php echo $v['id']; ?>" <?php if(($v['id'] == $crte_three['pid'])): ?> selected <?php endif; ?>><?php echo $v['cate_name']; ?></option>
                            <?php endforeach; ?>
                    </select>
                    <select name="cate_id" id="Three" class="input-xlarge">
                        <option value="">请选择三级分类</option>
                            <?php foreach($crte_three_all as $v): ?>
                               <option value="<?php echo $v['id']; ?>" <?php if(($v['id'] == $crte_three['id'])): ?> selected <?php endif; ?>><?php echo $v['cate_name']; ?></option>
                            <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="tab-pane fade in" id="desc">
                <div class="well">
                    <label>商品简介：</label>
                    <textarea id="editor" name="goods_body" style="width:1024px;height:500px;"><?php echo $goods['goods_body']; ?></textarea>
                </div>
            </div>
            <div class="tab-pane fade in" id="attr">
                <div class="well">
                    <label>商品类型：</label>
                    <select name="type_id" class="input-xlarge">
                        <option value="0">请选择</option>
                        <?php foreach($type as $v): ?>
                            <option value="<?php echo $v['id']; ?>" <?php if(($v['id'] == $goods['type_id'])): ?> selected <?php endif; ?>><?php echo $v['type_name']; ?></option>
                        <?php endforeach; ?>
                    </select>
                    <div id="attrs">
                        <?php foreach($attr as $v): ?>
                            <label><?php echo $v['attr_name']; ?></label>
                            <?php if(($v['attr_input_type'] == 0)): ?>

                                <input type="text" name="attr_value[<?php echo $v['id']; ?>][]" value="<?php echo $new_list[$v['id']][0]; ?>" class="input-xlarge">
                            <?php elseif(($v['attr_input_type'] == 1)): ?>

                                <select name="attr_value[<?php echo $v['id']; ?>][]">
                                    <?php foreach($v['attr_values'] as $value): ?>
                                        <option value="<?php echo $value; ?>" <?php if(($value == $new_list[$v['id']][0])): ?> selected="selected" <?php endif; ?>><?php echo $value; ?></option>
                                    <?php endforeach; ?>
                                </select>
                            <?php else: foreach($v['attr_values'] as $value): ?>

                                    <input type="checkbox" name="attr_value[<?php echo $v['id']; ?>][]" value="<?php echo $value; ?>" <?php if(in_array(($value), is_array($new_list[$v['id']])?$new_list[$v['id']]:explode(',',$new_list[$v['id']]))): ?> checked <?php endif; ?>><?php echo $value; endforeach; endif; endforeach; ?>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade in" id="pics">
                <div class="well">
                    <div>
                        [<a href="javascript:void(0);" class="add">+</a>]
                        商品图片：
                        <input type="file" name="goods_pics[]" value="" class="input-xlarge">
                    </div>
                    <?php foreach($goods_pics as $v): ?>
                        <div>
                            <img src="<?php echo $v['pics_small']; ?>" alt="">
                            <a href="javascript:void(0);" pics="<?php echo $v['id']; ?>" class="picsdel">删除</a>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
            <button class="btn btn-primary" type="submit">保存</button>
        </div>
    </form>
</div>
<script type="text/javascript">

        // 删除多个商品图片
        $(".picsdel").click(function(){

            var id = $(this).attr("pics");
            if(id == "") return;

            var that = this;
            $.ajax({
                url:"<?php echo url('admin/goods/picsdel'); ?>",
                data:"id="+id,
                success:function(res){
                    if(res.code != 10000)
                    {
                        alert(res.msg);
                        return;
                    }
                    $(that).parent().remove();
                }
            })
        })


        // 商品属性概况
        $("select[name=type_id]").change(function(){
            $("#attrs").html('');

            var id = $(this).val();
            if(id == 0) return;

            $.ajax({
                url:"<?php echo url('admin/attribute/getTree'); ?>",
                data:"id="+id,
                success:function(res){
                    if(res.code != 10000){
                        alert(res.msg);
                        return;
                    }
                    // 显示属性名称 遍历数组 拼接数组
                    // 定义空的变量 用来接受数据和 最后追加到页面
                    var str = '';
                    $.each(res.data,function(i,v){
                        str += "<label>"+ v.attr_name +"</label>";
                        // 判断attr_input_type 拼接input下拉列表多选框
                        if(v.attr_input_type == 0){

                            // input输入框
                            str += "<input type='text' name='attr_value["+ v.id +"][]' value='' class='input_xlarge'/>";
                        }else if(v.attr_input_type == 1){

                            // 下拉列表
                            str += '<select name="attr_value['+ id+'][]">';
                            str += '<option value="">===请选择===</option>'
                            $.each(v.attr_values,function(index,value){
                                str += '<option value="'+ value +'">'+ value +'</option>';
                            })
                            str += '</select>'
                        }else{

                            // 多选框
                            $.each(v.attr_values,function(index,value){
                                str += "<input type='checkbox' name='attr_value["+ v.id+"][]' value='"+ value +"'/>" + value;
                            })
                        }
                    });
                    $("#attrs").append(str);
                }
            })

        })

        // 三级分类
        $("#One").change(function(){
            $("#Two").html("<option>请选择二级分类</option>");
            $("#Three").html("<option>请选择三级分类</option>");

            var id = $("#One").val();

            if(id == "") return;

            console.log(11);
            $.ajax({
                url:"<?php echo url('admin/goods/getTree'); ?>",
                data:"id="+id,
                success:function(res){
                    if(res.code != 10000)
                    {
                        alert(res.msg);
                        return;
                    }

                    var html = "";
                    $.each(res.data,function(i,v){
                        html += "<option value='"+ v.id +"'>"+ v.cate_name +"</option>";
                    });

                    $("#Two").append(html);
                }
            })
        })
        $("#Two").change(function(){
            $("#Three").html("<option>请选择三级分类</option>");

            var id = $("#Two").val();

            if(id == "") return;

            console.log(11);
            $.ajax({
                url:"<?php echo url('admin/goods/getTree'); ?>",
                data:"id="+id,
                success:function(res){
                    if(res.code != 10000)
                    {
                        alert(res.msg);
                        return;
                    }

                    var html = "";
                    $.each(res.data,function(i,v){
                        html += "<option name='cate_id' value='"+ v.id +"'>"+ v.cate_name +"</option>";
                    });

                    $("#Three").append(html);
                }
            })
        })

        // 引入ueditor编辑器
        UE.getEditor('editor');

        $('.add').click(function(){
            var add_div = '<div>[<a href="javascript:void(0);" class="sub">-</a>]商品图片：<input type="file" name="goods_pics[]" value="" class="input-xlarge"></div>';
            $(this).parent().after(add_div);
        });
        $('.sub').live('click',function(){
            $(this).parent().remove();
        });
</script>


</body>
</html>